#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e6 + 10;
typedef long long ll;
ll a[N];
int main()
{
	ll n, m;cin >> n >> m;
	for (ll i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	sort(a + 1, a + 1 + n);
	if (m >= n)
	{
		cout << a[n] << endl;
	}
	else if (m == 0)
	{
		ll t = a[1] - 1;
		if (t > 0) cout << t << endl;
		else cout << "-1" << endl;
	}
	else if (a[m] == a[m + 1] || a[m] == 1e9)
	{
		cout << "-1" << endl;
	}
	else
	{
		cout << a[m] << endl;
	}
	return 0;
}
//1 3 3 5 7 10 20